package com.neusoft.actor.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.neusoft.actor.dto.OutgoingRequestWithClientDto;
import com.neusoft.actor.po.OutgoingRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OutgoingRequestDao extends BaseMapper<OutgoingRequest> {
    // 在这里可以定义一些自定义的SQL操作（如果有需要）
    @Select("<script>" +
            "SELECT o.request_id, o.remark, c.client_name, c.client_id, c.is_self_care, c.room_number, c.age, " +
            "       o.reason AS reason, o.departure_time, o.return_time, o.actual_return_time, o.status AS status " +
            "FROM clients c " +
            "JOIN outgoing_requests o ON c.client_id = o.client_id " +
            "WHERE 1=1 " +
            "<if test='clientName != null and clientName != \"\"'>" +
            "  AND c.client_name LIKE CONCAT('%', #{clientName}, '%') " +
            "</if> " +
            "<if test='isSelfCare != null and isSelfCare != \"\"'>" +
            "  AND c.is_self_care = #{isSelfCare} " +
            "</if> " +
            "</script>")
    List<OutgoingRequestWithClientDto> getOutgoingRequestsByConditions(
            @Param("clientName") String clientName,
            @Param("isSelfCare") String isSelfCare);
}